package com.gxitsky.exception;

/**
 * @author gxing
 * @desc 自定义业务异常
 * @date 2021/9/20 22:10
 */
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = -7385840093935800330L;

    /**
     * 500系统内部异常
     */
    private static final Error internalError = SystemError.SYS_INTERNAL_ERROR;

    private int code;

    private String message;

    public BusinessException() {
        this.code = internalError.getCode();
        this.message = internalError.getMessage();
    }

    public BusinessException(String message) {
        this.code = internalError.getCode();
        this.message = message;
    }

    public BusinessException(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public BusinessException(Error error) {
        this.code = error.getCode();
        this.message = error.getMessage();
    }

    public BusinessException(Error error, Throwable cause) {
        super(cause);
        this.code = error.getCode();
        this.message = error.getMessage();
    }

    public BusinessException(Throwable cause) {
        super(cause);
        this.code = internalError.getCode();
        this.message = cause.getMessage();
    }

    public BusinessException(int code, Throwable cause) {
        super(cause);
        this.code = code;
        this.message = internalError.getMessage();
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.code = internalError.getCode();
        this.message = message;
    }

    public BusinessException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}